#include "timer.h"

Timer::Timer() {
	running = false;
	timeFrequency = 0;
}

Timer::~Timer() {

}

void Timer::start() {	
	if (!running) {
		// Get the timer's frequency

#ifdef _WINDOWS
		LARGE_INTEGER li;
		QueryPerformanceFrequency(&li);

		// Get timer frequency per second
		timeFrequency = double(li.QuadPart);

		// Get the beginning time
		QueryPerformanceCounter(&beginning);
#endif

		running = true;
	}
}

void Timer::stop() {
	if (running) {
#ifdef _WINDOWS
		QueryPerformanceCounter(&end);
#endif
		running = false;
	}
}

double Timer::getElapsedTime() {
#ifdef _WINDOWS
	return (end.QuadPart - beginning.QuadPart) / timeFrequency;
#endif

	return 0;
}